package com.cjm.thread.zhonjianjian;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Thread.join()方法表示调用此方法的线程被阻塞， 仅当该方法完成以后， 才能继续运行
 */
public class Task2 implements Runnable {
    private LinkedBlockingQueue taskQueue = new LinkedBlockingQueue(1000);
    private AtomicBoolean running = new AtomicBoolean(true);
    public void submitTask(Object task) throws InterruptedException {
        taskQueue.put(task);
    }
    @Override
    public void run() {
        while (running.get()) {
            try {
                Object take = taskQueue.take();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            doSomething();
        }
    }

    private void doSomething() {

    }
}
